<style scoped lang='less'>
    .add-holiday-type{
        .ivu-input-wrapper{
            width: 35%;
        }
    }
</style>
<template>
    <div>
        
        <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
            <Form-item label="请假类型" prop="title">
                <i-input v-model="formValidate.title" placeholder="请输入请假类型"></i-input>
            </Form-item>
            <Form-item label="开始时间">
                <Row>
                    <i-col span="11">
                        <Date-picker type="datetime" placeholder="选择开始日期" @on-change="changeStartDate"></Date-picker>
                    </i-col>
                </Row>
            </Form-item>
            <Form-item label="结束时间">
                <Row>
                    <i-col span="11">
                        <Date-picker type="datetime" placeholder="选择结束日期" @on-change="changeEndDate"></Date-picker>
                    </i-col>
                </Row>
            </Form-item>
            <Form-item>
                <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
                <i-button type="ghost" style="margin-left: 8px" @click="jumpPage('','HolidayTypeList')">返回</i-button>
            </Form-item>
        </i-form>
    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    title: '',
                    startTime: '',
                    endTime: '',
                },
                ruleValidate: {
                    title: [
                        {required: true, message: '请假类型不能为空', trigger: 'blur'}
                    ],
                },
                papertypeArr:[],
            }
        },
        mounted: function () {},

        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            changeStartDate: function (date) {
                console.log(date);
                this.formValidate.startTime = date;
            },
            changeEndDate: function (date) {
                console.log(date);
                this.formValidate.endTime = date;

            },
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            addData: function (model) {
                let that = this;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.AddRestType, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {},
                        onCancel: () => {
                            baseUtil.pageJump(that,'','HolidayTypeList')
                        }
                    });
                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
            },

        }
    }
</script>
